<template>
  <div class="nickname-page">
    <div class="nickname-container animate__animated animate__fadeIn">
      <h1 class="animate__animated animate__bounceIn">模糊昵称生成器</h1>
      <p class="description">一键生成独特模糊昵称，让你的微信昵称与众不同。</p>
      
      <el-form @submit.prevent="generateBlurredNickname">
        <el-form-item label="输入昵称：">
          <el-input v-model="nickname" placeholder="输入你的昵称" required></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" native-type="submit">
            <el-icon><Magic /></el-icon>
            生成模糊昵称
          </el-button>
        </el-form-item>
      </el-form>

      <Transition name="fade">
        <div v-if="blurredNickname" class="result animate__animated animate__fadeInUp">
          <p class="tips">你的模糊昵称已生成：</p>
          <div class="blurred-nickname">{{ blurredNickname }}</div>
        </div>
      </Transition>

      <div class="example">
        <h3>示例</h3>
        <p>原昵称：Xiyueta网站<br>模糊昵称：X҈҈҈i҈҈҈y҈҈҈u҈҈҈e҈҈҈t҈҈҈a҈҈҈网҈҈҈站҈҈҈</p>
        <p><small>注：如在电脑浏览器中显示为乱码，请在手机上查看效果。</small></p>
      </div>

      <div class="button-group">
        <el-button @click="copyBlurredNickname" type="success" :disabled="!blurredNickname">
          <el-icon><CopyDocument /></el-icon>
          复制
        </el-button>
        <el-button @click="returnToHomepage" type="info">
          <el-icon><Back /></el-icon>
          返回首页
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { copyText } from '@/utils/clipboard'
// 从 @element-plus/icons-vue 导入所需图标
import { 
  Edit as Magic,  // 使用 Edit 图标替代
  DocumentCopy as CopyDocument, 
  Back 
} from '@element-plus/icons-vue'

const router = useRouter()
const nickname = ref('')
const blurredNickname = ref('')

const generateBlurredNickname = () => {
  if (!nickname.value) return
  blurredNickname.value = nickname.value.split('').map(char => char + '҈҈҈').join('')
}

const copyBlurredNickname = () => {
  if (blurredNickname.value) {
    copyText(blurredNickname.value)
  }
}

const returnToHomepage = () => {
  router.push('/')
}
</script>

<style lang="scss" scoped>
.nickname-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;

  .nickname-container {
    max-width: 600px;
    width: 96%;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
    padding: 30px;
    box-sizing: border-box;
    margin: 20px auto;

    h1 {
      text-align: center;
      color: #4a5568;
      font-size: 28px;
      margin-bottom: 20px;
      text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    }

    .description {
      text-align: center;
      color: #606266;
      margin-bottom: 30px;
    }

    .el-form {
      margin-bottom: 30px;

      .el-button {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 12px 20px;
        font-size: 16px;
      }
    }

    .result {
      margin: 20px 0;
      padding: 20px;
      background-color: #f0f9eb;
      border: 1px solid #e1f3d8;
      border-radius: 12px;

      .tips {
        color: #67c23a;
        font-weight: bold;
        margin-bottom: 10px;
      }

      .blurred-nickname {
        padding: 15px;
        background: white;
        border-radius: 8px;
        font-size: 16px;
        word-break: break-all;
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
      }
    }

    .example {
      margin: 30px 0;
      padding: 20px;
      background-color: #f4f4f5;
      border-radius: 12px;
      text-align: left;

      h3 {
        margin-top: 0;
        color: #409EFF;
      }

      p {
        margin: 10px 0;
        line-height: 1.6;

        small {
          color: #909399;
        }
      }
    }

    .button-group {
      display: flex;
      gap: 15px;
      margin-top: 20px;

      .el-button {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 12px 20px;
        font-size: 14px;

        .el-icon {
          font-size: 16px;
        }
      }
    }
  }
}

@media (max-width: 480px) {
  .nickname-page {
    padding: 10px;

    .nickname-container {
      padding: 20px;

      h1 {
        font-size: 24px;
      }

      .button-group {
        flex-direction: column;
      }
    }
  }
}
</style>
